package com.gitee.sop.layui.adminserver.module.background.develop.manager;

import com.gitee.sop.layui.adminserver.module.background.develop.entity.SysFunction;
import com.gitee.sop.layui.adminserver.module.background.develop.service.SysFunctionService;
import com.gitee.sop.layui.adminserver.plugins.cache.util.CacheUtil;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统功能缓存管理
 *
 * @author: huwei
 * @date: 2019/12/2 16:32
 * @version: 1.0.0
 */
@Component
public class SysFunctionCacheManager {
    @Lazy
    @Resource
    private SysFunctionService sysFunctionService;


    public List<SysFunction> listAll() {
        return CacheUtil.getOrPutIfAbsent("functionAll", () -> sysFunctionService.list(), SysFunctionCacheManager.class.getSimpleName());
    }

    public void updateBatchByIds(List<SysFunction> list) {
        sysFunctionService.updateBatchById(list);
        CacheUtil.remove("functionAll", SysFunctionCacheManager.class.getSimpleName());
    }
}
